package com.zhengke.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhengke.common.object.AjaxDone;
import com.zhengke.common.object.Result;
import com.zhengke.common.util.FileExport;
import com.zhengke.pojo.TvOrder;
import com.zhengke.service.IOrderService;

@Controller
@RequestMapping("order")
public class OrderController {

	@Autowired
	private IOrderService orderService;
	
	
	
	/**
	 * 去往listTvUserCredit页面sasdd
	 * @return
	 */
	@RequestMapping("queryCredit")
	public String toQueryTvUserCredit() {
		return "order/listTvUserCredit";
	}
	
	
	/**
	 * 跳转到修改用户信用页�?
	 * @return
	 */
	@RequestMapping("updateCredit")
	public String toXtgl04003(HttpServletRequest request, HttpServletResponse response, ModelMap model){
		String creditId = request.getParameter("creditId");
		System.out.println(creditId);
			model.put("creditId", creditId);
		return "order/updateCredit";
	}
	/**
	 * 跳转到查询用户信用详情页
	 * @return
	 */
	@RequestMapping("findCreditDetails")
	public String findDetails(HttpServletRequest request, HttpServletResponse response, ModelMap model){
		String creditId = request.getParameter("creditId");
		System.out.println(creditId);
			model.put("creditId", creditId);
		return "order/findCredit";
	}
	

	
	
	
	/**
	 * 修改订单状态为0
	 * @param orderId
	 * @return
	 */
	@RequestMapping(value="updateState0",method=RequestMethod.POST)
	@ResponseBody
	public Result updateOrderState0(Integer orderId) {
		Result rs = orderService.updateOrder(orderId, 0);
		return rs;
	}
	
	/**
	 * 修改费订单状态为20
	 * @param orderId
	 * @return
	 */
	@RequestMapping(value="updateState20",method=RequestMethod.POST)
	@ResponseBody
	public Result updateOrderState50(Integer orderId) {
		Result rs = orderService.updateOrder(orderId, 20);
		return rs;
	}
	

	
	/**
	 * 查询不良信用信息
	 * 
	 * @param map
	 * @return
	 */
	@RequestMapping(value="listTvUserCredit",method=RequestMethod.POST)
	@ResponseBody
	public Result queryTvUserCredit(String userId, String userName, String userPhone, String userCardNumber,int page, int limit) {
		Result rsResult = orderService.queryTvUserCredit(userId, userName, userPhone, userCardNumber, page, limit);
		return rsResult;
	}
	
	/**
	 * 查看用户不良信用订单详情
	 * 
	 * @param creditId
	 * @return
	 */
	@RequestMapping(value="listTvUserCreditDetails",method=RequestMethod.POST)
	@ResponseBody
	public Result findUserCreditDetails(int creditId,int page, int limit) {
		System.out.println(creditId+"==============");
		Result rs = orderService.findUserCreditDetails(creditId, page, limit);
		return rs;
	}
	
	/**
	 * 修改不良信用金额上限，信用次数上限
	 * 
	 * @param map
	 */
	@RequestMapping(value="updateUserCredit",method=RequestMethod.POST)
	@ResponseBody
	public AjaxDone updateUserCredit(Integer creditMoney, Integer creditSum, Integer creditId) {
	try{
		orderService.updateUserCredit(creditMoney, creditSum, creditId);
		return new AjaxDone("200", "修改成功");
	}catch(Exception e){
		e.printStackTrace();
		return new AjaxDone("300", "系统繁忙,请稍后重试!");
	}
	}
	
}
